﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-08-14 15:37:35
 * 功能：购买方式模板
**************************************************************************************/

using Game.BaseData;
using Game.Framework;
using System.Collections.Generic;
using UnityEngine;

public abstract class Purchase : MonoBehaviour
{
    protected Config.IAP m_Cfg;
    protected object m_Data;
    protected string m_IsoCurrencyCode = "USD";

    protected virtual void Awake()
    {
        LogManager.Log($"当前购买方式：{GetType().Name}", "Purchase");
        DontDestroyOnLoad(gameObject);
    }

    protected virtual void Start()
    {
        m_Cfg = BaseDataMgr.Instance.Cfg.iap;
    }

    public virtual void Buy(string id, object data = null)
    {
        m_Data = data;
    }

    protected void ReportBI(string id, string name, int type, float revenue, string currency, string orderNum, string status, string msg)
    {
        var biData = new Dictionary<string, object>
        {
            { "item_id", id },
            { "item_name", name },
            { "type", type },
            { "revenue", revenue.ToString(System.Globalization.CultureInfo.InvariantCulture) },
            { "currency", currency },
            { "order_num", orderNum },
            { "purchase_status", status },
            { "msg", msg },
        };
        NativeInteraction.Instance.SendBILog("purchase", biData);
    }

    protected void ResetData()
    {
        m_Data = null;
    }

    public string IsoCurrencyCode => m_IsoCurrencyCode;
}